package cn.bdqn.hospital.filter;

import javax.servlet.*;
import java.io.IOException;

public class ExceptionFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("异常处理过滤器启动完成。。。");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        try{
            filterChain.doFilter(servletRequest, servletResponse);
        }catch (Exception e){
            servletRequest.setAttribute("errorInfo",e.getMessage());
            servletRequest.getRequestDispatcher("/404.jsp").forward(servletRequest, servletResponse);
        }
    }

    @Override
    public void destroy() {
        System.out.println("异常处理过滤器销毁。。。");
    }
}

